﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView.Export;

namespace Thi_nghiem_nen_ket_co_thong_tin
{
    public partial class Ket_qua_thi_nghiem : System.Web.UI.UserControl
    {
        public const string SESSION_DATA = "Ket_qua_thi_nghiem_data";
        public int NumOfData {
            get { return string.IsNullOrEmpty(HnoOfData.Value)?0:Convert.ToInt32(HnoOfData.Value); }
            set { HnoOfData.Value = value.ToString(); }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        public void LoadData()
        {
            var objTn = (ObjThiNghiem) Session[ObjThiNghiem.SESSION_NAME];
            if (objTn == null||NumOfData==0)
            {
                dataGridView_ket_qua.DataSource = null;
                dataGridView_ket_qua.DataBind();
                return;
            }

            var dt = new DataTable();
            dt.Columns.Add("P");
            dt.Columns.Add("e");
            dt.Columns.Add("a");
            dt.Columns.Add("t90");
            dt.Columns.Add("d90");
            dt.Columns.Add("Cv");
            dt.Columns.Add("Kv");
            dt.Columns.Add("mv");

            for (int j = 0; j <= NumOfData; j++)
            {
                var dr = dt.NewRow();
                dr["P"] = objTn.P[j];
                dr["e"] = objTn.hsr[j];
                dr["a"] = objTn.a[j];
                dr["t90"] = objTn.T50[j];
                dr["d90"] = objTn.S50[j];
                dr["Cv"] = objTn.Cv[j];
                dr["Kv"] = objTn.Kv[j];
                dr["mv"] = objTn.mv[j];
                dt.Rows.Add(dr);
            }

            dataGridView_ket_qua.DataSource = dt;
            dataGridView_ket_qua.DataBind();
        }       
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            gridExport.ExportedRowType = GridViewExportedRowType.All;
            string name = "KetQuaThiNghiem_" + DateTime.Now.ToString("dd_MM_YY hh:mm:ss:ff");
            gridExport.WriteXlsxToResponse(name);
        }
    }
}